﻿using Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using DAL;

namespace BLL
{
    class FirstOperation
    {
        public List<DeviceConnMessage> _DeviceConnList;
        public PLCWorkAddress _PLCWorkAddress;
        public WorkMessage _WorkMessage;
        FileOperate _FileOperate = new FileOperate();

        public void FirstDecvieWrite()
        {

            #region 设备
            _DeviceConnList = new List<DeviceConnMessage>()
            {
            new DeviceConnMessage()
            {
                DeviceName="PLC",
                ConnMode=ConnectWay.Tcp,

                ServerAdress="192.168.0.1",
                BindAdress="",
                BindPort=0
            },
            new DeviceConnMessage()
            {
               DeviceName="上位机客户端",
                ConnMode=ConnectWay.Tcp,
                ServerAdress="127.0.0.1",
                ServerPort=1000,
                BindAdress="",
                BindPort=0

            },
            new DeviceConnMessage()
            {
                DeviceName="CCD客户端",
                ConnMode=ConnectWay.Tcp,

                ServerAdress="192.168.0.1",
                ServerPort=1000,
                BindAdress="",
                BindPort=0

            },
             new DeviceConnMessage()
            {
                DeviceName="扫码抢客户端",
                ConnMode=ConnectWay.Tcp,

                ServerAdress="192.168.0.1",
                ServerPort=1000,
               BindAdress="",
                BindPort=0

            },
             new DeviceConnMessage()
            {
               DeviceName="机器人客户端",
                ConnMode=ConnectWay.Tcp,

                ServerAdress="192.168.0.1",
                ServerPort=10000,
                BindAdress="",
                BindPort=0

            },
            new DeviceConnMessage()
            {
               DeviceName="测重串口",
                ConnMode=ConnectWay.Com,

                PortName="COM1",
                BaudRate=9600,
                DataBits=8,
                StopBits=System.IO.Ports.StopBits.None,
                Parity=System.IO.Ports.Parity.None,
                 ComMessageMode=ComMessageMode.Ascill
            },
           new DeviceConnMessage()
            {
                DeviceName="测高串口",
                ConnMode=ConnectWay.Com,

                PortName="COM2",
                BaudRate=9600,
                DataBits=8,
                StopBits=System.IO.Ports.StopBits.None,
                Parity=System.IO.Ports.Parity.None,
                ComMessageMode=ComMessageMode.Ascill
            }
            };
            #endregion
            _FileOperate.WriteDriveConnMessage(_DeviceConnList);
        }
        public void FirstPLCAddressWrite()
        {
            _PLCWorkAddress = new PLCWorkAddress()
            {
                CallAGV1 = "DB160.DBX2660.0",
                CallAGV2 = "DB160.DBX2660.0",
                ReportWork = "DB160.DBX2660.0",
                StartWorkState = "DB160.DBX2660.0",
                ReportWorkState = "DB160.DBX2660.0",
                OrderNum = "DB160.DBW2660",
                AllowReportWork = "DB160.DBX2660.0",
                AllowNextStation = "DB160.DBX2660.0"
            };
            _FileOperate.WritePLCAddress(_PLCWorkAddress);
        }

        public void FirstWorkMessageWrite()
        {
            _WorkMessage = new WorkMessage()
            {
                OrderMessage = new SendWorkOrderInfo()
                {
                    MaterialCodification = "123",
                    PalletNo = "234",
                    Quantity = 1,
                    SerialNumbers = new List<string>() { "1234" },
                    StationNo = "345",
                    WorkOrderNo = "678"

                },
                SationNo = "32507",
                StartMessage = new StartInterface()
                {
                    CatchPlaceNo = new string[] { "1" ,"2","1231"},
                    SerialNo = "122343",
                    StationNo = "122343",
                    WorkOrderNo = "234"

                },
                ReportMessage = new MESsignal()
                {
                    BadQty = "123",
                    WorkOrderNo = "123",
                    GoodQty = "123",
                    StationNo = "123",
                    ManufacturingItems = new List<KeyValueInfo>() { new KeyValueInfo() { Key="123",Value="123"},new KeyValueInfo() { Key="123",Value="123"} },
                    CatchPlaceNo = new string[] { "123","123" },
                    TargetPlaceNo = "123",
                    InspectionItems = new List<KeyValueInfo>() { new KeyValueInfo() { Key="123",Value="123"},new KeyValueInfo() { Key="123",Value="123"} },
                    CatchData = new List<Catch>() { new Catch() { CatchPlaceNo="123",CatchQty=123,MaterialCodification="123"} },
                    SerialNo = "123"
                },
                AGVMessage = new MESDefaultList()
                {
                    MaterialCodification = "",
                    PalletNo="",
                    Priority="",
                    SerialNo="",
                    Tag="",
                    StationNo="",
                    SupplyMaterialCodifications=new string[] { },
                    WorkOrderNo=""
                },
            };
            _FileOperate.WriteWorkMssage(_WorkMessage);
        }
        public void FirstWriteAGVGoodsWrite()
        {
            AGVNO aGVGoodsNO = new AGVNO()
            {
                AGV1_202Up = new string[] { },
                AGV1_501Up = new string[] { },
                AGV2_202Up = new string[] { },
                AGV2_501Up = new string[] { },
                AGV1_202Down = new string[] { },
                AGV1_501Down = new string[] { },
                AGV2_202Down = new string[] { },
                AGV2_501Down = new string[] { },
            };
            _FileOperate.WriteAGVGoodsMessage(aGVGoodsNO);
        }
    }
}
